
<div class="templatemo-content-wrapper">
	<div class="templatemo-content">
		<ol class="breadcrumb">
			<li><a href="<?=site_url()?>/product/index">商品管理</a></li>
			<li class="active">编辑拆分商品</li>
		</ol>
		<div class="row margin-bottom-30">
			<div class="col-md-12">
				<ul class="nav nav-pills">
					<li class="active"><a href="<?=site_url()?>/product/dividelist">返回拆分商品列表</a></li>
				</ul>
			</div>
		</div>
		<div class="row">
			<div class="col-md-12">
				<div class="table-responsive">
					<h4 class="margin-bottom-15">编辑拆分商品</h4>
					<form role="form" id="templatemo-preferences-form"
						onsubmit="return false;">
						<div class="row">
							<div class="col-md-6 margin-bottom-15">
								<label for="firstName" class="control-label">箱类商品名称</label> <input
									type="text" class="form-control" id="name1" value="<?php echo $divide['name1'].'-'.$divide['productid']; ?>">
							</div>
							<div class="col-md-6 margin-bottom-15">
								<label for="lastName" class="control-label">单份商品名称</label> <input
									type="text" class="form-control" id="name2" value="<?php echo $divide['name2'].'-'.$divide['newproductid']; ?>">
							</div>
							<div class="col-md-6 margin-bottom-15">
								<label for="firstName" class="control-label">数量</label> <input
									type="text" class="form-control" id="amount" value="<?php echo $divide['amount']; ?>">
							</div>
						</div>
						<div class="row templatemo-form-buttons">
							<div class="col-md-12">
								<input type="hidden"  id="divideid" value="<?php echo $divide['id']; ?>">
								<button type="submit" class="btn btn-primary" id="submit_btn">修改</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
	$(document).ready(function() {
		//var cache = {};
		$("#name1").autocomplete({
			minLength:1,
			source:function(request,response){
				/*var term = request.term;
				if ( term in cache ) {
         			 response( cache[ term ] );
         			 return;
       			 }*/
       			 $.ajax({
                    url:'<?php echo site_url('product/getProducts')?>',
                    type : "post",
                    dataType: "json",
                    data:{
                        name: request.term
                    },
                    success: function( data ) {
                        //cache[ term ] = data;
                        response($.map(data, function(item) {
    		            return {
    		                 label: item.name+'-'+item.description,
    		                 value: item.name+ '-' + item.id
    		             }
    		         }));
                    }
                });
			}
		});
		$("#name2").autocomplete({
			minLength:1,
			source:function(request,response){
				/*var term = request.term;
				if ( term in cache ) {
         			 response( cache[ term ] );
         			 return;
       			 }*/
       			 $.ajax({
                    url:'<?php echo site_url('product/getProducts')?>',
                    type : "post",
                    dataType: "json",
                    data:{
                        name: request.term
                    },
                    success: function( data ) {
                        //cache[ term ] = data;
                        response($.map(data, function(item) {
    		            return {
    		                 label: item.name+'-'+item.description,
    		                 value: item.name+ '-' + item.id
    		             }
    		         }));
                    }
                });
			}
		});
		$("#submit_btn").click(function() {
			var id = $("#divideid").val();
			var name1 = $("#name1").val();
			var name2 = $("#name2").val();
			var amount = $("#amount").val();
			$.ajax({
				url : '<?php echo site_url('product/savedivide')?>',
				type : "post",
				async : true,
				data : {
					'id':id,
					'name1' : name1,
					'name2' : name2,
					'amount' : amount
				},
				dataType : "json",
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
					}else{
						alert(data.msg);
					}
				}
			});
		});
	}); 
</script>